/*
2GWVS a free web vulnerability scanner.
Copyright (C) 2008  Grigis Gaetan

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
*/

#ifndef _PREFERENCES_H_
#define _PREFERENCES_H_

#include <QtGui>
#include <QWidget>
#include "ui_preferences.h"
#include <QDebug>
class Preferences : public QWidget, private Ui::preferences
{
    Q_OBJECT
	    
    public:
    	//so what it is too bad to write in .h?? i'm too lazy to create a .cpp
        Preferences() : QWidget() {
        	setupUi(this);
			this->setWindowIcon(QIcon(":/img/edit_pref.ico"));
        	QSettings settings;
        	//PROXY SETTINGS
        	if(settings.value("network/useproxy").toBool())
        		proxy_use->setChecked(true);
        	proxy_cra_addr->setText(settings.value("network/cra_host").toString());
        	proxy_sca_addr->setText(settings.value("network/sca_host").toString());
        	
        	proxy_cra_port->setValue(settings.value("network/cra_port").toInt());
        	proxy_sca_port->setValue(settings.value("network/sca_port").toInt());
        	
        	proxy_cra_user->setText(settings.value("network/cra_name").toString());
        	proxy_sca_user->setText(settings.value("network/sca_name").toString());
        	
        	proxy_cra_pass->setText(settings.value("network/cra_pass").toString());
        	proxy_sca_pass->setText(settings.value("network/sca_pass").toString());
        	//CRAWLERS SETTINGS
        	cra_cra_ua->setText(settings.value("crawler/user-agent","Firefox 3").toString());
        	cra_ct->setText(settings.value("crawler/content-type","text/html;text/plain").toString());
        	
	        if(settings.value("crawler/crawl_type","html").toString()=="xml")
				crawl_xml_type->setChecked(true);
			else
				crawl_html_type->setChecked(true);
			//pushButt
        }

    private slots:
    void on_preference_save_clicked()
    {
    	QSettings settings;
    	//PROXY SETTINGS
    	if(proxy_use->isChecked())
    		settings.setValue("network/useproxy",1);
    	else
    		settings.setValue("network/useproxy",0);
    		
    	settings.setValue("network/cra_host",proxy_cra_addr->text());
		settings.setValue("network/sca_host",proxy_sca_addr->text());
			
		settings.setValue("network/cra_port",proxy_cra_port->text());
		settings.setValue("network/sca_port",proxy_sca_port->text());
			
		settings.setValue("network/cra_name",proxy_cra_user->text());
		settings.setValue("network/sca_name",proxy_sca_user->text());
		
		settings.setValue("network/cra_pass",proxy_cra_pass->text());
		settings.setValue("network/sca_pass",proxy_sca_pass->text());
		//CRAWLERS SETTINGS
		settings.setValue("crawler/user-agent",cra_cra_ua->text());
		settings.setValue("crawler/content-type",cra_ct->text());
		
		if(crawl_xml_type->isChecked())
			settings.setValue("crawler/crawl_type","xml");
		else
			settings.setValue("crawler/crawl_type","html");
    }
    void on_preference_cancel_clicked() {this->close();}
};


#endif // !_PREFERENCES_H_
